package com.xudow.app.dynamicstate_old.module.guide;

import android.content.Intent;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.xudow.app.R;
import com.xudow.app.dynamicstate_old.widget.CircleTextView;
import com.xudow.app.newui.home.HomeActivity;
import com.xudow.app.util.PrefUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by ske on 2016/5/23.
 * 第一步
 */
public class RoleActivity extends AppCompatActivity implements View.OnClickListener {
    @BindView(R.id.text_parent)
    CircleTextView parents;
    @BindView(R.id.text_student)
    CircleTextView student;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide_role);
        ButterKnife.bind(this);
        if (PrefUtils.isFirstLaunch(this)) {
            setupView();
        } else {
            startActivity(new Intent(this, HomeActivity.class));
        }
    }

    private void setupView() {
        parents.setOnClickListener(this);
        student.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.text_parent) {
            PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("isStudent", false).apply();
            startActivityForResult(new Intent(this, ClazzActivity.class), 10086);
        } else if (view.getId() == R.id.text_student) {
            PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("isStudent", true).apply();
            startActivityForResult(new Intent(this, ClazzActivity.class), 10086);
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 10086 && resultCode == RESULT_OK) {
            finish();
        }
    }
}
